﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace HDUSampling.HDUControls.HTools.LoadingFrm
{
    /// <summary>
    /// BusyDecorator.xaml 的交互逻辑
    /// </summary>
    public partial class BusyDecorator : UserControl
    {
        public BusyDecorator()
        {
            InitializeComponent();
            busy = new LoadingUtil(this.canvas_bu);
        }
        LoadingUtil busy;
        bool isstart = false;
        public bool IsBusy
        {
            get { return isstart; }
            set {
                if (value)
                {
                    busy.StartDecorator();
                    Thread th = new Thread(() => {
                        int ka = 0;
                        while (isstart)
                        {
                            Thread.Sleep(400);
                            txt.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                if (ka % 2 == 0)
                                {
                                    txt.Text = $".";
                                }
                                else
                                {
                                    txt.Text = $"...";
                                }
                                ka++;
                            }));
                        }
                    });
                    th.Start();
                    isstart = true;
                }
                else
                {
                    busy.StopDecorator();
                    isstart = false;
                }
            }
        }
    }
}
